<?php
class memberApi extends baseApi{

	public function hook_menu_admin_ext($callback=flase){
        $list=array(
            '会员管理' =>array(
                0 => array('name'=>'会员列表','url'=>url('member/user_list/index'),'sequence'=>0),
                1 => array('name'=>'会员组列表','url'=>url('member/user_group/index'),'sequence'=>1),
                ),
            );
        if($callback){
            return $list;
        }
        $list=api('admin','menu_sort',$list);
        echo api('admin','menu_html',array('data'=>$list,'title'=>'会员管理'));
    }

    public function hook_user_menu_base(){
    }
    
    public function hook_user_menu_manage(){
        return array(
            0 => array('name'=>'短信息','url'=>url('member/message/index'),'sequence'=>0),
            1 => array('name'=>'联系人','url'=>url('member/friends/index'),'sequence'=>1),
            2 => array('name'=>'收藏夹','url'=>url('member/collection/index'),'sequence'=>2),
            );
    }

    public function hook_user_menu_info(){
        return array(
            0 => array('name'=>'个人资料','url'=>url('member/information/index'),'sequence'=>0),
            1 => array('name'=>'密码修改','url'=>url('member/information/password'),'sequence'=>1),
            );
    }

    //设置排除登录
    public function hook_user_login_exclude(){
        return array(
                'login'=>array('index','login','login_html'),
                'register'=>array('index','agreement','data','get_province'),
                'index'=>array('home'),
                'forget'=>array('index','data','success'),
                'email'=>array('post'),
                'transaction'=>array('recharge_syn','recharge_ayn'),
        );
    }

    //后台权限设置
    public function hook_menu_system(){
        return array(
            0 => array('name'=>'会员中心设置','url'=>url('member/user_system/index'),'sequence'=>2),
        );
    }

    public function hook_purview_admin()
    {
        return array(
            'user_system'=>array(
                'name'=>'会员中心设置',
                'auth'=>array(
                    'index'=>'设置',
                ),
            ),
            'user_group'=>array(
                'name'=>'会员组管理',
                'auth'=>array(
                    'index'=>'列表',
                    'add'=>'添加',
                    'edit'=>'编辑',
                    'del'=>'删除',
                ),
            ),
            'user_list'=>array(
                'name'=>'会员管理',
                'auth'=>array(
                    'index'=>'列表',
                    'add'=>'添加',
                    'edit'=>'编辑',
                    'del'=>'删除',
                ),
            ),
        );
    }

    //会员权限设置
    public function hook_purview_user()
    {
        return array(
            'message'=>array(
                'name'=>'短信息',
                'auth'=>array(
                    'index'=>'列表',
                    'add'=>'发送',
                    'batch'=>'删除',
                ),
            ),
            'friends'=>array(
                'name'=>'联系人',
                'auth'=>array(
                    'index'=>'列表',
                    'edit'=>'备注',
                    'del'=>'删除',
                ),
            ),
            'collection'=>array(
                'name'=>'收藏夹',
                'auth'=>array(
                    'index'=>'列表',
                    'add'=>'添加',
                    'del'=>'删除',
                ),
            ),
            'information'=>array(
                'name'=>'个人资料',
                'auth'=>array(
                    'index'=>'查看信息',
                    'info_save'=>'保存信息',
                    'password'=>'密码修改',
                    
                ),
            ),
        );
    }

    //公共赋值处理
    public function hook_user_tpl_assign(){
        return model('menu')->user_menu();
    }

    //权限检测扩展
    public function hook_user_check_login(){
       model('login')->check_purview();
    }

    //注册地区
    public function region_name($id)
    {
        return model('region')->get_name($id);
    }

    public function region_list($data)
    {
        return model('region')->region_list($data['pid'],$data['type']);
    }

    //判断是否登录
    public function login_if()
    {
        return model('login')->is_login();
    }

    //检测登录失败跳转或ajax提示
    public function login_check()
    {
        return model('login')->check_login();
    }

    //获取当前用户信息
    public function login_user_info()
    {
        return model('login')->user_info();
    }

    //获取会员信息
    public function user_info($uid)
    {
        return model('user_list')->info($uid);
    }

    //开放模块获取
    public function get_model($data)
    {
        $model=$data['model'];
        $action=$data['action'];
        $parameter=$data['parameter'];
        if(is_array($parameter)){
            switch (count($parameter))
            {
                case 0:
                    return model($model)->$action($parameter);
                    break;
                case 1:
                    return model($model)->$action($parameter[0]);
                    break;
                case 2:
                    return model($model)->$action($parameter[0],$parameter[1]);
                    break;
                case 3:
                    return model($model)->$action($parameter[0],$parameter[1],$parameter[2]);
                    break;
                case 4:
                    return model($model)->$action($parameter[0],$parameter[1],$parameter[2],$parameter[3]);
                    break;
                case 5:
                    return model($model)->$action($parameter[0],$parameter[1],$parameter[2],$parameter[3],$parameter[4]);
                    break;
            }
        }else if(!empty($parameter)){
            return model($model)->$action($parameter);
        }else {
            return model($model)->$action();
        }

    }
}